<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h2>Vue2中 Object.defineProperty 的响应式</h2>
  <div>
    <input type="text" id="input">
    <div><span id="span"></span></div>
  </div>
  
</body>
<script>
  let obj = {}
  Object.defineProperty(obj, "username", {
    get: function() {
      console.log('Get')
    },
    set: function(value) {
      console.log('Set:' + value)
      document.getElementById('span').innerText = value
    }
  })

  document.getElementById('input').addEventListener('keyup', function() {
    console.log(event)
    obj.username = event.target.value
  })
</script>
</html>